/*
 * MVCClienteEnLinea.java
 *
 * Created on 26 de marzo de 2009, 08:12 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.nextel.project.cliente.mvc;

import com.nextel.project.Configuracion;
import com.nextel.project.cliente.ControlCliente;
import com.nextel.ui.OLabel;
import com.nextel.ui.OSoftKey;
import com.nextel.ui.OTextField;
import com.nextel.ui.OUILook;
import pe.com.nextel.idioma.IdiomaManager;
import pe.com.nextel.main.MVCAction;

/**
 *
 *
 */
public class MVCClienteEnLinea extends MVCAction {
    
    /**
     * Creates a new instance of MVCClienteEnLinea
     */
    private OTextField txtCodigo;
    private OSoftKey cmdNull, cmdExit;
    private boolean flagForm;
    
    
    protected void createView() {
        cmdNull = new OSoftKey(IdiomaManager.getInstance().getMensaje(IdiomaManager.JAVA_BUSCAR) ); // "Buscar"
        cmdExit = new OSoftKey(Configuracion.BOTON_ATRAS );
        
        formulario.setTitle(IdiomaManager.getInstance().getMensaje(IdiomaManager.JAVA_CLIENTES_ONLINE), OUILook.PLAIN_SMALL_TITLE);//"Clientes - Online"
        formulario.addSoftKey(cmdNull);
        formulario.addSoftKey(cmdExit);
    }
    
    protected void createItems() {
        flagForm = true;
        formulario.add(new OLabel(IdiomaManager.getInstance().getMensaje(IdiomaManager.JAVA_CODIGO)+":", OUILook.PLAIN_SMALL_TEXT));//C\u00F3digo
        txtCodigo = new OTextField(25, OUILook.PLAIN_SMALL_TEXT, OTextField.ANY|OTextField.UPPERCASE);
        formulario.add(txtCodigo);
        flagForm = true;
        
        //System.out.println("clienteenlinea.Trhread.count=" + Thread.activeCount( ));
    }
    
    
    public void performAction(OSoftKey c)  {
        if (flagForm) {
            if (c == cmdExit) {
                flagForm = false;
                destroy();
                ControlCliente.getInstance().setCurrent( ControlCliente.getInstance().mvcClienteBusqueda );
                
            } else if (c == cmdNull) {
                flagForm = false;
                if( txtCodigo.getText().equals("") ) {
                    ControlCliente.getInstance().showMensaje(IdiomaManager.getInstance().getMensaje(IdiomaManager.JAVA_INGRESE_CODIGO), formulario);//"Debe ingresar el c\u00F3digo"
                    flagForm = true;
                    return;
                }
                
                String campo = txtCodigo.getText().toUpperCase( ) ;
                destroy();
 
                ControlCliente.getInstance().buscarClienteOnline(campo);
                
            }
        }
        
    }
    
}
